//
//  KnowMoreFCell.m
//  NewPro
//
//  Created by 何荧红 on 2019/1/16.
//  Copyright © 2019 何荧红. All rights reserved.
//

#import "KnowMoreFCell.h"

@interface KnowMoreFCell ()

@property (weak, nonatomic) IBOutlet UILabel *countlab;
@property (weak, nonatomic) IBOutlet UIImageView *stateimg;
@property (weak, nonatomic) IBOutlet UILabel *Detaillab;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *WithHeight;
@property (weak, nonatomic) IBOutlet UIView *DisLineView;

@end

@implementation KnowMoreFCell

- (void)awakeFromNib {
    [super awakeFromNib];
}
- (void)setModel:(KnowMoreModel *)Model{
    _Model = Model;
    if (self.Search.length > 0) {
        if (([_Model.SubCont rangeOfString:self.Search].location != NSNotFound) || ([_Model.Whydo rangeOfString:self.Search].location != NSNotFound)) {
            if ([_Model.SubCont rangeOfString:self.Search].location != NSNotFound) {
                NSMutableAttributedString *string = [[NSMutableAttributedString alloc]initWithString:_Model.SubCont];
                [string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:[_Model.SubCont rangeOfString:self.Search]];
                self.countlab.attributedText = string;
            }else{
                self.countlab.attributedText = nil;
                self.countlab.text = _Model.SubCont;
            }
            if ([_Model.Whydo rangeOfString:self.Search].location != NSNotFound) {
                NSMutableAttributedString *string = [[NSMutableAttributedString alloc]initWithString:_Model.Whydo];
                [string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:[_Model.Whydo rangeOfString:self.Search]];
                self.Detaillab.attributedText = string;
            }else{
                self.Detaillab.attributedText = nil;
                self.Detaillab.text = _Model.Whydo;
            }
        }else{
            self.countlab.attributedText = nil;
            self.Detaillab.attributedText = nil;
            self.countlab.text = _Model.SubCont;
            self.Detaillab.text = _Model.Whydo;
        }
    }else{
        self.countlab.attributedText = nil;
        self.Detaillab.attributedText = nil;
        self.countlab.text = _Model.SubCont;
        self.Detaillab.text = _Model.Whydo;
    }
}
- (void)setIsPush:(BOOL)isPush{
    _isPush = isPush;
    if (_isPush) {
        self.stateimg.image = [UIImage imageNamed:@"灰色上箭头"];
        self.WithHeight.constant = _Model.CellHeight;
        
        self.Detaillab.hidden = NO;
        self.DisLineView.hidden = NO;
    }else{
        self.stateimg.image = [UIImage imageNamed:@"灰色下箭头"];
        self.WithHeight.constant = 0;
        
        self.Detaillab.hidden = YES;
        self.DisLineView.hidden = YES;
    }
}
- (IBAction)PushOrPull:(UIButton *)sender {
    self.isPush = !self.isPush;
    if (self.SendPushBlock) self.SendPushBlock(self.isPush);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
